package ui;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import Work.Jdbc;

public class Enroll extends JFrame implements ActionListener {
	private JButton readerenroll;
	private JButton librarianenroll;
	private JButton sysadminenroll;
	private JButton returnbutton;
	// 创建数据库连接类对象
	Jdbc db = new Jdbc();

	public Enroll() {
		JFrame jFrame = new JFrame("注册面板");
		jFrame.setLayout(new BorderLayout());
		JPanel jp1 = new JPanel(new GridLayout(2, 2, 10, 10));// 设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("注册面板"));
		// this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("注册面板");
		setSize(300, 200);
		setLocationRelativeTo(null);

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		readerenroll = new JButton("读者注册");
		librarianenroll = new JButton("图书管理员注册");
		sysadminenroll = new JButton("系统管理员注册");

		jp1.add(readerenroll);
		jp1.add(librarianenroll);
		jp1.add(sysadminenroll);
		getContentPane().add(jp1, BorderLayout.CENTER);
		JPanel jp2 = new JPanel();
		returnbutton = new JButton("返回");
		returnbutton.addActionListener(this);
		jp2.add(returnbutton);
		add(jp2, BorderLayout.SOUTH);

		readerenroll.addActionListener(this);
		librarianenroll.addActionListener(this);
		sysadminenroll.addActionListener(this);

		this.setVisible(true);
	}

	@Override

	public void actionPerformed(ActionEvent e) {
		Enroll1 Enroll1 = new Enroll1();
		if (e.getSource() == readerenroll) {
			this.dispose();
			Enroll1.readerenroll();
		} else if (e.getSource() == sysadminenroll) {
			this.dispose();
			Enroll1.librarianenroll();
		} else if (e.getSource() == librarianenroll) {
			this.dispose();
			Enroll1.sysadminenroll();
		}  else if (e.getSource() == returnbutton) {
			this.dispose();
			new Begin();
		}
	}
}